package com.yzh.encapsulation;

/**
 * @author 于振晗
 * @title: Person
 * @description: TODO 学生类封装
 * @date 2020年08月25日
 * @path com.yzh.encapsulation
 */
public class Person {
    private String name;
    private String sex;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this. sex = sex.substring(0,1);
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age>130 || age<1){
            this.age = 18;
            return;
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}
